import edge_tts
from .base_tts import BaseTTS

class EdgeTTS(BaseTTS):
    """
    Implements Text-to-Speech using the edge-tts library.
    """
    @staticmethod
    def get_name():
        return "Edge TTS"

    async def save(self, text, output_file, voice):
        """
        Saves the text as an MP3 file using the specified voice.
        """
        communicate = edge_tts.Communicate(text, voice)
        await communicate.save(output_file)

    @staticmethod
    async def get_voices():
        """
        Gets and returns a list of supported voices, grouped by language and gender.
        """
        voices = await edge_tts.list_voices()
        # We can sort or filter the voices as needed, for example by language
        voices.sort(key=lambda v: (v['Locale'], v['Gender']))
        return voices